<?php
namespace app\shop\controller\plus;
use app\common\service\Result;
use app\shop\model\plus\model\AgentSet;
/**
 * 分销控制器
 */
class Agent
{
    /**
     * 插件列表
     */
    public function getSet()
    {
        $set = AgentSet::find(request()->app_id);
        $set['level'] = $set['level'] ?? 3;
        return Result::success($set);
    }

    public function save()
    {
        $data = request()->param();
        $data['level'] = $data['level'] ?: 3;
        $set = AgentSet::find(request()->app_id);
        if ($set) {
            $set->save($data);
        } else {
            $data['app_id'] = request()->app_id;
            $set = AgentSet::create($data);
        }
        return Result::success();
    }
}